package com.vrv.app.cyberspace.common.ddio;

import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/12/21
 * @Modified By:
 */
public class DDIORunnable implements Runnable {

    private Object target;
    private Method method;
    private Object param;

    public DDIORunnable(Object target, String methodName,Object paramv, Class paramz) throws NoSuchMethodException {
        this.target = target;
        this.param = paramv;
        if (param != null) {
            this.method = target.getClass().getDeclaredMethod(methodName, paramz);
        } else {
            this.method = target.getClass().getDeclaredMethod(methodName);
        }
    }

    @Override
    public void run() {
        try {
            ReflectionUtils.makeAccessible(method);
            if (param != null) {
                method.invoke(target, param);
            } else {
                method.invoke(target);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
